﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using MySql.Data.MySqlClient;

public partial class Module_Login : System.Web.UI.UserControl
{
    protected bool CheckIsLogined()
    {
      
        if (Session["AsUserName"]!=null && Session["AsUserName"].ToString()!= "")
        {
            Label1.Text = Session["AsUserName"].ToString();;
            return true;
        } 
        else
        {
            return false;
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        if(CheckIsLogined()==true)
        {
            MultiView_Login.SetActiveView(View_Logined1);
        }
        else
        {
            MultiView_Login.SetActiveView(View_UnLogin1);
        }
       
    }

    protected void LinkButton_Logout_Click(object sender, EventArgs e)
    {
        Session.RemoveAll();
        MultiView_Login.SetActiveView(View_UnLogin1);
    }
    protected void Button_Submit_Click(object sender, EventArgs e)
    {
        MysqlHelp DBLogin = new MysqlHelp();
        DataTable UserTable = new DataTable();
        UserTable = DBLogin.GetDatabysql("select * from user where username='" + TextBox_UserName.Text + "'and password='" + TextBox_PassWord.Text + "'");
         if(UserTable.Rows.Count!=0)
        {
            Session["AsUserName"] = UserTable.Rows[0]["username"];
            MultiView_Login.SetActiveView(View_Logined1);
        }
         else
         {
             Session.RemoveAll();
             Response.Write("<script>alert('登陆失败！');history.go(-1);</script>");
         }
         CheckIsLogined();
    }
    protected void Button_Register_Click(object sender, EventArgs e)
    {
    }
}
